package ru.spb.osll.myfit.common;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class PageExecutingResultTest {
  
  private PageExecutingResult m_result = new PageExecutingResult("1");
  private Table m_table1 = new Table();
  private Table m_table2 = new Table();
  ArrayList<Table> m_tables = new ArrayList<Table>();  
  
  @Test
  public void testConstructor () {
    assertTrue(m_result.getID() == "1");
    assertTrue(m_result.getCounts().isNull() == true);    
    assertTrue(m_result.getExecutedTables().size() == 0);
    assertTrue(m_result.getState() == PageExecutingResult.PageExecutingState.NOT_STARTED);    
  }
  
  @Test
  public void testAddExecutedTable(){
    assertTrue(m_result.getExecutedTables().size() == 0);    
    m_result.addExecutedTable(m_table1);
    assertTrue(m_result.getExecutedTables().size() == 1);
    assertTrue(m_result.getExecutedTables().get(0) == m_table1);
  }
  
  @Test
  public void testAddAllExecutedTeble(){    
    m_tables.add(m_table2);
    assertTrue(m_result.getExecutedTables().size() == 0);
    m_result.addExecutedTable(m_table1);
    assertTrue(m_result.getExecutedTables().size() == 1);
    assertTrue(m_result.getExecutedTables().get(0) == m_table1);
    m_result.addAllExecutedTable(m_tables);
    assertTrue(m_result.getExecutedTables().size() == 2);    
    assertTrue(m_result.getExecutedTables().get(0) == m_table1);
    assertTrue(m_result.getExecutedTables().get(1) == m_table2);
  }
  
  @Test
  public void testGetExecutedTables(){    
    m_tables.add(m_table1);
    m_tables.add(m_table2);
    assertTrue(m_result.getExecutedTables().size() == 0);
    m_result.addAllExecutedTable(m_tables);
    assertTrue(m_result.getExecutedTables().size() == 2);
    assertTrue(m_result.getExecutedTables().get(0) == m_table1);
    assertTrue(m_result.getExecutedTables().get(1) == m_table2);
    m_tables.clear();
    List<Table> m_tables2 = m_result.getExecutedTables();
    assertTrue(m_tables2.size() == 2);
    assertTrue(m_tables2.get(0) == m_table1);
    assertTrue(m_tables2.get(1) == m_table2);
  }
  
  @Test
  public void testRemoveAllTables(){    
    m_tables.add(m_table1);
    m_tables.add(m_table2);
    assertTrue(m_result.getExecutedTables().size() == 0);
    m_result.addAllExecutedTable(m_tables);
    assertTrue(m_result.getExecutedTables().size() == 2);
    assertTrue(m_result.getExecutedTables().get(0) == m_table1);
    assertTrue(m_result.getExecutedTables().get(1) == m_table2);
    m_result.removeAllTables();
    assertTrue(m_result.getExecutedTables().size() == 0);
  }
  
}
